<template>
    <div class="home">
        home
        <h2>这是在home中本身的data数据：{{ name }}</h2>
        <button @click="fire()">点击发射</button><br /><br />
        <button @click="returnRoute">路由参数</button>
        <Two>
            <template slot-scope="scopeData">
                <h4>{{ scopeData.twoData + '123456' }}</h4> </template
            ><br />
            <template v-slot:to></template>>
            <h3 slot="to"></h3>
        </Two>
    </div>
</template>

<script>
import EventBus from '@/js/eventBus'
import Two from '@/views/componentTest/Two'

export default {
    name: 'Home',
    components: {
        Two
    },
    data() {
        return {
            name: '张三'
        }
    },
    methods: {
        fire() {
            //在$emit中第一个参数为自定义事件名，第二个参数为要传递的值
            EventBus.$emit('fireName', this.name)
        },
        returnRoute() {
            this.$router.push({
                name: 'Two',
                query: {
                    param: 123
                }
            })
        }
    },
    // destroyed() {
    //   this.fire();
    // },
    beforeDestroy() {
        this.fire()
    }
}
</script>
